package com.pan.creational.abstractfactory.factory.child;

import com.pan.creational.abstractfactory.entity.Common;
import com.pan.creational.abstractfactory.factory.AbstractFactory;
import com.pan.creational.abstractfactory.utils.AbstractFactoryUtils;

import java.lang.reflect.InvocationTargetException;

public class ColorFactory extends AbstractFactory {


    @Override
    public Common get(String type) {
        String colorName = AbstractFactoryUtils.INSTANCE.getClassname(type);
        try {
            Object color = Class.forName(colorName).getConstructor().newInstance();
            return (Common) color;
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
